﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using CodeGenBL.Function;
using ProjectDAL.Entities;

namespace CodeGenBL.Dto
{
    [DataContract]
    public class ProjectDto
    {
        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public int UserId { get; set; }
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public int StyleId { get; set; }
        [DataMember]
        public int Platform { get; set; } 
        [DataMember]
        public string DbServerName { get; set; }
        [DataMember]
        public string DbName { get; set; }
        [DataMember]
        public string DbUserName { get; set; }
        [DataMember]
        public string DbPassword { get; set; }
        [DataMember]
        public int Version { get; set; }
        [DataMember]
        public DateTime CreateTime { get; set; }
        [DataMember]
        public DateTime LastUpdate { get; set; }
    }

    public static class ProjectModelExt
    {
        public static Project TransformToProjectModel(this ProjectDto projectDto)
        {
            if (Validation.isInvalidCharacters(projectDto.Name))
                throw new Exception("Invalid Charecters");
            return new Project
            {
                Id = projectDto.Id,
                Name = projectDto.Name,
                User = new User { Id = projectDto.UserId },
                Platform = projectDto.Platform,
                StyleId = projectDto.StyleId,
                DbServerName = projectDto.DbServerName,
                DbUserName = projectDto.DbUserName,
                DbName = projectDto.DbName,
                DbPassword = projectDto.DbPassword,
                Version = projectDto.Version,
                CreateDate = projectDto.CreateTime,
                LastUpdate = projectDto.LastUpdate
            };
        }

        
    }
}
